package net.pimpas.web.jsf.renderers.legend.html;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import net.pimpas.web.jsf.components.UIComponentPimpasBase;
import net.pimpas.web.jsf.components.legend.UILegend;
import net.pimpas.web.jsf.renderers.RendererBase;
import net.pimpas.web.jsf.renderers.util.html.HtmlRendererBase;
import net.pimpas.web.jsf.util.ComponentUtils;

public class HtmlLegendRenderer extends RendererBase {
	
	@Override
	public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
		if(!component.isRendered()) return;
		if(!ComponentUtils.isCorrectComponentType(component, UILegend.class)) return;
		
		context.getResponseWriter().startElement("legend", component);
		
		HtmlRendererBase.writeBaseHtmlAttributes(context, (UIComponentPimpasBase) component);
	}
	
	@Override
	public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
		if(!ComponentUtils.isCorrectComponentType(component, UILegend.class)) return;
		
		context.getResponseWriter().endElement("legend");
	}
}